<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebSocket 双向通信演示</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background: white;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .status {
            padding: 10px;
            border-radius: 4px;
            margin-bottom: 20px;
            font-weight: bold;
        }
        .connected {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .disconnected {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        .messages {
            height: 300px;
            overflow-y: auto;
            border: 1px solid #ddd;
            padding: 10px;
            margin-bottom: 20px;
            background-color: #fafafa;
        }
        .message {
            margin-bottom: 10px;
            padding: 8px;
            border-radius: 4px;
        }
        .welcome {
            background-color: #e7f3ff;
            border-left: 4px solid #007bff;
        }
        .broadcast {
            background-color: #fff3cd;
            border-left: 4px solid #ffc107;
        }
        .private {
            background-color: #f8d7da;
            border-left: 4px solid #dc3545;
        }
        .system {
            background-color: #e2e3e5;
            border-left: 4px solid #6c757d;
            font-style: italic;
        }
        .input-group {
            display: flex;
            margin-bottom: 10px;
        }
        .input-group input {
            flex: 1;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px 0 0 4px;
        }
        .input-group button {
            padding: 10px 20px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 0 4px 4px 0;
            cursor: pointer;
        }
        .input-group button:hover {
            background-color: #0056b3;
        }
        .controls {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            margin-top: 20px;
        }
        .control-btn {
            padding: 10px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-weight: bold;
        }
        .connect-btn {
            background-color: #28a745;
            color: white;
        }
        .disconnect-btn {
            background-color: #dc3545;
            color: white;
        }
        .ping-btn {
            background-color: #17a2b8;
            color: white;
        }
        .clear-btn {
            background-color: #6c757d;
            color: white;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>WebSocket 双向通信演示</h1>
        
        <div id="status" class="status disconnected">
            状态: 未连接
        </div>
        
        <div id="messages" class="messages"></div>
        
        <div class="input-group">
            <input type="text" id="messageInput" placeholder="输入消息..." disabled>
            <button id="sendBtn" disabled>发送广播</button>
        </div>
        
        <div class="input-group">
            <input type="text" id="targetIdInput" placeholder="目标用户ID（私聊）" disabled>
            <input type="text" id="privateMessageInput" placeholder="私聊消息..." disabled>
            <button id="sendPrivateBtn" disabled>发送私聊</button>
        </div>
        
        <div class="controls">
            <button id="connectBtn" class="control-btn connect-btn">连接</button>
            <button id="disconnectBtn" class="control-btn disconnect-btn" disabled>断开连接</button>
            <button id="pingBtn" class="control-btn ping-btn" disabled>发送心跳</button>
            <button id="clearBtn" class="control-btn clear-btn">清空消息</button>
        </div>
    </div>

    <script src="/socket.io/socket.io.js"></script>
    <script src="script.js"></script>
</body>
</html>